// announceManagement.js
import request from '@/utils/request'

const baseUri = '/announceMannage'

// Announce Management Module
const AnnounceManagement = {
  /**
   * Get a list of announcements with optional filters
   * @param {Object} params - Filter parameters (title, created, userId)
   * @returns {Promise} - API response promise
   */
  list(searchMap) {
    return request({
      url: `${baseUri}/list`,
      method: 'post',
      data:searchMap
    })
  },

  /**
   * Find an announcement by ID
   * @param {number|string} id - Announcement ID
   * @returns {Promise} - API response promise
   */
  find(id) {
    return request({
      url: `${baseUri}/find`,
      method: 'get',
      params: { id }
    })
  },

  /**
   * Find all announcements
   * @returns {Promise} - API response promise
   */
  findAll() {
    return request({
      url: `${baseUri}/findAll`,
      method: 'get'
    })
  },

  /**
   * Add a new announcement
   * @param {Object} announceMannage - Announcement data
   * @returns {Promise} - API response promise
   */
  add(announceMannage) {
    return request({
      url: `${baseUri}/add`,
      method: 'post',
      data: announceMannage
    })
  },

  /**
   * Update an existing announcement
   * @param {Object} announceMannage - Announcement data
   * @returns {Promise} - API response promise
   */
  update(id,announceMannage) {
    
    //判断是否有ID，没有就是新增
    if(id===null || id===''){
        return this.add(announceMannage)
    }

    return request({
      url: `${baseUri}/update`,
      method: 'post',
      data: announceMannage
    })
  },

  /**
   * Remove an announcement by ID
   * @param {number|string} id - Announcement ID
   * @returns {Promise} - API response promise
   */
  remove(id) {
    return request({
      url: `${baseUri}/delete`,
      method: 'get',
      params: { id }
    })
  },

  /**
   * Batch remove announcements
   * @param {Object} batchDeleteDto - DTO containing IDs of announcements to be deleted
   * @returns {Promise} - API response promise
   */
  batchRemove(batchDeleteDto) {
    return request({
      url: `${baseUri}/batchRemove`,
      method: 'post',
      data: batchDeleteDto
    })
  }
}

export default AnnounceManagement